package dev.spb3.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import dev.spb3.model.Employee;
import dev.spb3.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/employees")
public class EmployeeController {
    private EmployeeService employeeService;
    @Autowired
    public EmployeeController(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }
    @PostMapping("/save")
    public boolean save(Employee employee) {
        return employeeService.save(employee);
    }
    @PostMapping("/saveOrUpdate")
    public boolean saveOrUpdate(Employee employee) {
        return employeeService.saveOrUpdate(employee);
    }
    @DeleteMapping("/remove/{id}")
    public boolean remove(@PathVariable long id) {
        return employeeService.removeById(id);
    }
    @PutMapping("/update")
    public boolean update(Employee employee) {
        return employeeService.updateById(employee);
    }
    @GetMapping("/get/{id}")
    public Employee get(@PathVariable long id) {
        return employeeService.getById(id);
    }
    @GetMapping("/list")
    public List<Employee> list() {
        return employeeService.list();
    }

    @GetMapping("/page")
    public IPage<Employee> getEmployeesByPage(
            @RequestParam(name = "pageNo",defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize) {
        return employeeService.getEmployeesByPage(pageNo, pageSize);
    }
}
